package chapter02;

import java.math.BigDecimal;

/**
 * Created by a on 2017/6/8.
 */
public class Test025 {
    public static void main(String[] args) {
        //二进制数无法精确表示所有小数，在商业领域中使用BigDecimal做精确计算
        double money = 2;
        double price = 1.1;
        double result = money - price;
        System.out.println("非精确的计算:");
        System.out.println("剩余金额:"+result);
        //精确浮点数的解决方案
        BigDecimal money1 = new BigDecimal("2");
        BigDecimal price1 = new BigDecimal("1.1");
        BigDecimal result1 = money1.subtract(price1);
        System.out.println("精确计算");
        System.out.println("剩余金额:"+result1);

    }
}
